#!/bin/bash

# Git 操作脚本
echo "=== Git 操作菜单 ==="
echo "1. 添加所有更改并提交"
echo "2. 推送到远程仓库"
echo "3. 拉取远程更新"
echo "4. 查看当前状态"
echo "5. 查看提交历史"
echo "6. 创建新分支"
echo "7. 切换分支"
echo "8. 合并分支"
echo "9. 删除分支"
echo "0. 退出"

read -p "请选择操作 (0-9): " choice

case $choice in
    1)
        read -p "请输入提交信息: " commit_msg
        git add .
        git commit -m "$commit_msg"
        echo "✅ 已添加并提交更改"
        ;;
    2)
        read -p "请输入分支名称 (默认为当前分支): " branch
        if [ -z "$branch" ]; then
            branch=$(git branch --show-current)
        fi
        git push origin "$branch"
        echo "✅ 已推送到远程仓库"
        ;;
    3)
        git pull
        echo "✅ 已拉取远程更新"
        ;;
    4)
        git status
        ;;
    5)
        git log --oneline -10
        ;;
    6)
        read -p "请输入新分支名称: " new_branch
        git checkout -b "$new_branch"
        echo "✅ 已创建并切换到分支 $new_branch"
        ;;
    7)
        read -p "请输入要切换的分支名称: " branch_name
        git checkout "$branch_name"
        echo "✅ 已切换到分支 $branch_name"
        ;;
    8)
        read -p "请输入要合并的分支名称: " merge_branch
        git merge "$merge_branch"
        echo "✅ 已合并分支 $merge_branch"
        ;;
    9)
        read -p "请输入要删除的分支名称: " delete_branch
        git branch -d "$delete_branch"
        echo "✅ 已删除分支 $delete_branch"
        ;;
    0)
        echo "👋 退出脚本"
        exit 0
        ;;
    *)
        echo "❌ 无效选择，请重新运行脚本"
        exit 1
        ;;
esac

echo ""
echo "🎉 操作完成！"